package com.doge.controller.wx;

import com.doge.bean.base.BaseRespVo;
import com.doge.bean.bo.cart.AddCartBO;
import com.doge.bean.bo.cart.CheckedCartBO;
import com.doge.bean.bo.cart.UpdateCartBO;
import com.doge.bean.pojo.cart.Cart;
import com.doge.bean.pojo.cart.CartExample;
import com.doge.bean.pojo.goods.Goods;
import com.doge.bean.pojo.user.User;
import com.doge.bean.vo.cart.WxCheckOutVO;
import com.doge.bean.vo.cart.WxIndexVO;
import com.doge.service.wx.cart.WxCartService;
import com.doge.service.wx.cart.WxCartServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @program: project2-wechat-mall
 * @description: 购物车
 * @author: zhu lei
 * @create: 2021-12-02 10:08
 **/
@RestController
@RequestMapping("wx/cart")
public class WxCartController {

    @Autowired
    WxCartServiceImpl wxCartService;

    @RequestMapping("goodscount")
    public BaseRespVo goodsCount() {
        Integer data = wxCartService.getCountsByCart();
        return BaseRespVo.ok(data);
    }

    @RequestMapping("add")
    public BaseRespVo add(@RequestBody AddCartBO addCartBO) {
        int data= wxCartService.addCart(addCartBO);

        return BaseRespVo.ok(data);
    }

    @RequestMapping("index")
    public BaseRespVo index() {
        WxIndexVO wxIndexVO = wxCartService.cartIndexById();
        return BaseRespVo.ok(wxIndexVO);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody UpdateCartBO updateCartBO) {
        wxCartService.updateCartByUser(updateCartBO);
        return BaseRespVo.ok();
    }

    @RequestMapping("checked")
    public BaseRespVo check(@RequestBody CheckedCartBO checkedCartBO) {
        WxIndexVO wxIndexVO = wxCartService.checkedCartUser(checkedCartBO);
        return BaseRespVo.ok(wxIndexVO);
    }

    @RequestMapping("fastadd")
    public BaseRespVo fastAdd(@RequestBody AddCartBO addCartBO) {
        Integer data = wxCartService.fastAdd(addCartBO);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("checkout")
    public BaseRespVo checkOut(Integer cartId,Integer addressId,Integer couponId,Integer userCouponId,Integer grouponRulesId) {
        WxCheckOutVO wxCheckOutVO = wxCartService.checkOutCart(cartId,addressId,couponId,userCouponId,grouponRulesId);
        return BaseRespVo.ok(wxCheckOutVO);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody CheckedCartBO checkedCartBO) {
        WxIndexVO wxIndexVO = wxCartService.deleteCart(checkedCartBO);
        return BaseRespVo.ok(wxIndexVO);
    }
}